cap program drop plot_mainf_prem
program define plot_mainf_prem

	shell mkdir -p $release/plots/mainf_prem
	shell mkdir -p $release/plots_tables/mainf_prem
	
	* Graphing
	foreach m in 2 3 4 {		
		use "$sumstats_data_path/serff.dta", clear
		keep if best_guess_metal == `m'
		** Unweighted
                #delimit ;
		graph box p, 
			over(sg_vs_indiv) 
			over(year)
			box(1, fcolor("white") lcolor("black")) box(2, color("black"))
			marker(1, mfcolor("white") mlcolor("black")) marker(2,mcolor("black"))
			xsize(2) ysize(2) legend(off) ytitle("premium ($/month)") ylab(150(100)600, gmax gmin)
			asyvars
		; 
		#delimit cr
		graph export "$release/plots/mainf_prem/`m'.eps", replace
	        
    ** weighted
    #delimit ;
    graph box p [fweight = count],
      over(sg_vs_indiv)
      over(year)
	box(1, fcolor("white") lcolor("black")) box(2, color("black"))
	marker(1, mfcolor("white") mlcolor("black")) marker(2,mcolor("black"))
      xsize(2) ysize(2) legend(off) ytitle("premium ($/month)") ylab(150(100)600, gmax gmin)
      asyvars
    ;
    #delimit cr
    graph export "$release/plots/mainf_prem/w_`m'.eps", replace

		* Accompanying table
		** Unweighted
		preserve
		#delimit ;
		collapse 
			(count) obs = p   
			(mean)  mean = p 
			(p50)   p50 = p  
			(sd)    std_dev = p,
			by(sg_vs_indiv year);
		#delimit cr		
		ren (sg_vs_indiv) (market)
		order market year
		export delimited $release/plots_tables/mainf_prem/`m'.csv, replace
		restore
		** Weighted
		preserve
		#delimit ;
		collapse 
			(count) obs = p   
			(mean)  w_mean = p 
			(p50)   w_p50 = p  
			(sd)    std_dev = p
			[fweight=count], 
			by(sg_vs_indiv year);
		#delimit cr		
		ren (sg_vs_indiv) (market)
		order market year
		export delimited $release/plots_tables/mainf_prem/w_`m'.csv, replace	
		restore
		
	}

end
